import java.util.HashMap;

public class LC3M {

    public int lengthOfLongestSubstring(String s) {
        if (s.length()==0)return 0;
        char[] ch=s.toCharArray();
        int count=0;
        int start=0;
        int end=0;
        int n=s.length();
        HashMap<Character,Integer> map=new HashMap<>();
        while (end<n){
            if (map.containsKey(ch[end]) && map.get(ch[end])>=start){
                start=map.get(ch[end])+1;
            }
            map.put(ch[end],end);
            count=Math.max(count,end-start+1);
            end++;
        }
        return count;
    }

}
